package com.munhrasoft.elearning.business.entities;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;

@Entity
@NamedQueries(value = {
    @NamedQuery(name = "findAllGroupEntity", query = "SELECT grp FROM GroupEntity grp"),
    @NamedQuery(name = "findByGroupName", query = "SELECT grp FROM GroupEntity grp WHERE lower(grp.itsName) "
            + "LIKE :name") })

@SequenceGenerator(name = "groupEntitySeq", initialValue = 1, allocationSize = 1)
public class GroupEntity {

    private static final String USER_GROUP_COLUMN = "itsGroupEntity";

    @Id
    @Column(name = "name", length = 20)
    private String              itsName;

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = USER_GROUP_COLUMN)
    private List<UserEntity>    itsUsers;
    
    @Override
    public boolean equals(Object obj) {
        if (this.getItsName() == ((GroupEntity) obj).getItsName()) {
            return true;
        } else {
            return false;
        }
    }

    public String getItsName() {
        return itsName;
    }

    public void setItsName(String itsName) {
        this.itsName = itsName;
    }

    public List<UserEntity> getItsUsers() {
        return itsUsers;
    }

    public void setItsUsers(List<UserEntity> itsUsers) {
        this.itsUsers = itsUsers;
    }

}
